import { request } from 'umi';

/**
 * 权限列表
 */
export async function listPermission(
  params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
    name?: string;
  },
  options?: Record<string, any>,
) {
  return request<ADMIN.PermissionList>('/v1/permissions', {
    method: 'GET',
    params: { ...params },
    ...(options || {}),
  });
}

/**
 * 新建权限
 */
export async function addPermission(body: ADMIN.Permission, options?: Record<string, any>) {
  return request<ADMIN.Permission>('/v1/permission/create', {
    method: 'POST',
    data: {
      ...body,
    },
    ...(options || {}),
  });
}

/**
 * 修改权限
 */
export async function editPermission(
  id: number | undefined,
  body: ADMIN.Permission,
  options?: Record<string, any>,
) {
  return request<ADMIN.Permission>('/v1/permission/edit/' + id, {
    method: 'PUT',
    data: {
      ...body,
    },
    ...(options || {}),
  });
}

/**
 * 删除权限
 * @param id
 * @param options
 * @returns
 */
export async function deletePermission(id: number | undefined, options?: Record<string, any>) {
  return request<ADMIN.Success>('/v1/permission/delete/' + id, {
    method: 'DELETE',
    ...(options || {}),
  });
}

/**
 * 一键生成路由权限
 */
export async function generatePermission(options?: Record<string, any>) {
  return request<ADMIN.Success>('/v1/permission/generate', {
    method: 'POST',
    ...(options || {}),
  });
}
